package com.ease.database.ddl.initializer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.Test;

import com.ease.common.vo.MapParameter;
import com.ease.document.freemarker.FreeMarkerUtil;
import com.obas.business.analogy.util.AnalogyTableNameUtil;
import com.obas.model.type.AnalogyDimensionAttributeType;
import com.obas.model.type.AnalogyDimensionType;
import com.obas.model.type.DimensionAttributeType;
import com.obas.model.type.ProcessDimensionType;
import com.obas.model.type.TimeDimensionType;

public class AnalogyStatementInitializer {// extends ApplicationContextUserContextTest {

	@Test
	public void init() {
		AnalogyDimensionType[] analogyDimensionTypes = AnalogyDimensionType.enabledValues();
		
		
		
		//10_X_TABLE_INDEX.ftl
		
//		for(TimeDimensionType timeDimensionType: new TimeDimensionType[]{ //
//				TimeDimensionType.HOUR,//
//				TimeDimensionType.DAY,//
//				TimeDimensionType.WEEK}){
//				for(ProcessDimensionType processDimensionType: new ProcessDimensionType[]{ //
//						ProcessDimensionType.KQI_AGG,//
//						ProcessDimensionType.KQI_ACC,//
//						ProcessDimensionType.KQI_ACC_CYCLE}){
//				
//					for (AnalogyDimensionType analogyDimensionType : analogyDimensionTypes) {
//						MapParameter parameter = new MapParameter();
//						parameter.put("sourceTable", AnalogyTableNameUtil.tableName(analogyDimensionType, timeDimensionType, processDimensionType));
//						
//			
//						DimensionAttributeType[] dimensionAttributeTypeArray = AnalogyDimensionAttributeType.getByAnalogyDimensionType(analogyDimensionType);
//						List<DimensionAttributeType> dimensionAttributeTypes1 = Arrays.asList(dimensionAttributeTypeArray);
//						List<DimensionAttributeType> dimensionAttributeTypes = new ArrayList<DimensionAttributeType>();
//						dimensionAttributeTypes.addAll(dimensionAttributeTypes1);
////						if (dimensionAttributeTypes.contains(DimensionAttributeType.LOCATION_ID)) {
////							dimensionAttributeTypes.remove(DimensionAttributeType.LOCATION_ID);
////						}
//						parameter.put("dimensionAttributeTypes", dimensionAttributeTypes);
//						System.out.println(FreeMarkerUtil.processFile(AnalogyStatementInitializer.class, "10_X_TABLE_INDEX.ftl", parameter));
//					}
//			}
//			}
		
		//20_HOUR_KPI_AGG-DAY_KPI_AGG.ftl
//		
//		for (AnalogyDimensionType analogyDimensionType : analogyDimensionTypes) {
//			MapParameter parameter = new MapParameter();
//			parameter.put("sourceTable", AnalogyTableNameUtil.tableName(analogyDimensionType, TimeDimensionType.HOUR, ProcessDimensionType.KPI_AGG));
//			parameter.put("targetTable", AnalogyTableNameUtil.tableName(analogyDimensionType, TimeDimensionType.DAY, ProcessDimensionType.KPI_AGG));
//
//			DimensionAttributeType[] dimensionAttributeTypeArray = AnalogyDimensionAttributeType.getByAnalogyDimensionType(analogyDimensionType);
//			List<DimensionAttributeType> dimensionAttributeTypes1 = Arrays.asList(dimensionAttributeTypeArray);
//			List<DimensionAttributeType> dimensionAttributeTypes = new ArrayList<DimensionAttributeType>();
//			dimensionAttributeTypes.addAll(dimensionAttributeTypes1);
//			if (dimensionAttributeTypes.contains(DimensionAttributeType.LOCATION_ID)) {
//				dimensionAttributeTypes.remove(DimensionAttributeType.LOCATION_ID);
//			}
//			parameter.put("dimensionAttributeTypes", dimensionAttributeTypes);
//			System.out.println(FreeMarkerUtil.processFile(AnalogyStatementInitializer.class, "20_HOUR_KPI_AGG-DAY_KPI_AGG.ftl", parameter));
//		}

		
		//30_DAY_KPI_AGG-WEEK_KPI_AGG.ftl
//		
//		for (AnalogyDimensionType analogyDimensionType : analogyDimensionTypes) {
//			MapParameter parameter = new MapParameter();
//			parameter.put("sourceTable", AnalogyTableNameUtil.tableName(analogyDimensionType, TimeDimensionType.DAY, ProcessDimensionType.KPI_AGG));
//			parameter.put("targetTable", AnalogyTableNameUtil.tableName(analogyDimensionType, TimeDimensionType.WEEK, ProcessDimensionType.KPI_AGG));
//
//			DimensionAttributeType[] dimensionAttributeTypeArray = AnalogyDimensionAttributeType.getByAnalogyDimensionType(analogyDimensionType);
//			List<DimensionAttributeType> dimensionAttributeTypes1 = Arrays.asList(dimensionAttributeTypeArray);
//			List<DimensionAttributeType> dimensionAttributeTypes = new ArrayList<DimensionAttributeType>();
//			dimensionAttributeTypes.addAll(dimensionAttributeTypes1);
//			if (dimensionAttributeTypes.contains(DimensionAttributeType.LOCATION_ID)) {
//				dimensionAttributeTypes.remove(DimensionAttributeType.LOCATION_ID);
//			}
//			parameter.put("dimensionAttributeTypes", dimensionAttributeTypes);
//			System.out.println(FreeMarkerUtil.processFile(AnalogyStatementInitializer.class, "30_DAY_KPI_AGG-WEEK_KPI_AGG.ftl", parameter));
//		}
		
		//40_KPI_AGG_SUMMATION.ftl
//		
//		for(TimeDimensionType timeDimensionType: new TimeDimensionType[]{ //
//				TimeDimensionType.HOUR,//
//				TimeDimensionType.DAY,//
//				TimeDimensionType.WEEK}){
//		for (AnalogyDimensionType analogyDimensionType : analogyDimensionTypes) {
//			MapParameter parameter = new MapParameter();
//			parameter.put("sourceTable", AnalogyTableNameUtil.tableName(analogyDimensionType, timeDimensionType, ProcessDimensionType.KPI_AGG));
//			
//
//			DimensionAttributeType[] dimensionAttributeTypeArray = AnalogyDimensionAttributeType.getByAnalogyDimensionType(analogyDimensionType);
//			List<DimensionAttributeType> dimensionAttributeTypes1 = Arrays.asList(dimensionAttributeTypeArray);
//			List<DimensionAttributeType> dimensionAttributeTypes = new ArrayList<DimensionAttributeType>();
//			dimensionAttributeTypes.addAll(dimensionAttributeTypes1);
//			if (dimensionAttributeTypes.contains(DimensionAttributeType.LOCATION_ID)) {
//				dimensionAttributeTypes.remove(DimensionAttributeType.LOCATION_ID);
//			}
//			parameter.put("dimensionAttributeTypes", dimensionAttributeTypes);
//			System.out.println(FreeMarkerUtil.processFile(AnalogyStatementInitializer.class, "40_KPI_AGG_SUMMATION.ftl", parameter));
//		}
//		}
		
		//41_HOUR_KPI_AGG-HOUR_KQI_AGG.ftl
//		
//		for (AnalogyDimensionType analogyDimensionType : analogyDimensionTypes) {
//			MapParameter parameter = new MapParameter();
//			parameter.put("sourceTable", AnalogyTableNameUtil.tableName(analogyDimensionType, TimeDimensionType.HOUR, ProcessDimensionType.KPI_AGG));
//			parameter.put("targetTable", AnalogyTableNameUtil.tableName(analogyDimensionType, TimeDimensionType.HOUR, ProcessDimensionType.KQI_AGG));
//
//			DimensionAttributeType[] dimensionAttributeTypeArray = AnalogyDimensionAttributeType.getByAnalogyDimensionType(analogyDimensionType);
//			List<DimensionAttributeType> dimensionAttributeTypes1 = Arrays.asList(dimensionAttributeTypeArray);
//			List<DimensionAttributeType> dimensionAttributeTypes = new ArrayList<DimensionAttributeType>();
//			dimensionAttributeTypes.addAll(dimensionAttributeTypes1);
//			if (dimensionAttributeTypes.contains(DimensionAttributeType.LOCATION_ID)) {
//				dimensionAttributeTypes.remove(DimensionAttributeType.LOCATION_ID);
//			}
//			parameter.put("dimensionAttributeTypes", dimensionAttributeTypes);
//			System.out.println(FreeMarkerUtil.processFile(AnalogyStatementInitializer.class, "41_HOUR_KPI_AGG-HOUR_KQI_AGG.ftl", parameter));
//		}

		
		//42_DAY_KPI_AGG-DAY_KQI_AGG.ftl
//		
//		for (AnalogyDimensionType analogyDimensionType : analogyDimensionTypes) {
//			MapParameter parameter = new MapParameter();
//			parameter.put("sourceTable", AnalogyTableNameUtil.tableName(analogyDimensionType, TimeDimensionType.DAY, ProcessDimensionType.KPI_AGG));
//			parameter.put("targetTable", AnalogyTableNameUtil.tableName(analogyDimensionType, TimeDimensionType.DAY, ProcessDimensionType.KQI_AGG));
//
//			DimensionAttributeType[] dimensionAttributeTypeArray = AnalogyDimensionAttributeType.getByAnalogyDimensionType(analogyDimensionType);
//			List<DimensionAttributeType> dimensionAttributeTypes1 = Arrays.asList(dimensionAttributeTypeArray);
//			List<DimensionAttributeType> dimensionAttributeTypes = new ArrayList<DimensionAttributeType>();
//			dimensionAttributeTypes.addAll(dimensionAttributeTypes1);
//			if (dimensionAttributeTypes.contains(DimensionAttributeType.LOCATION_ID)) {
//				dimensionAttributeTypes.remove(DimensionAttributeType.LOCATION_ID);
//			}
//			parameter.put("dimensionAttributeTypes", dimensionAttributeTypes);
//			System.out.println(FreeMarkerUtil.processFile(AnalogyStatementInitializer.class, "42_DAY_KPI_AGG-DAY_KQI_AGG.ftl", parameter));
//		}

		//43_WEEK_KPI_AGG-WEEK_KQI_AGG.ftl
//		
//		for (AnalogyDimensionType analogyDimensionType : analogyDimensionTypes) {
//			MapParameter parameter = new MapParameter();
//			parameter.put("sourceTable", AnalogyTableNameUtil.tableName(analogyDimensionType, TimeDimensionType.WEEK, ProcessDimensionType.KPI_AGG));
//			parameter.put("targetTable", AnalogyTableNameUtil.tableName(analogyDimensionType, TimeDimensionType.WEEK, ProcessDimensionType.KQI_AGG));
//
//			DimensionAttributeType[] dimensionAttributeTypeArray = AnalogyDimensionAttributeType.getByAnalogyDimensionType(analogyDimensionType);
//			List<DimensionAttributeType> dimensionAttributeTypes1 = Arrays.asList(dimensionAttributeTypeArray);
//			List<DimensionAttributeType> dimensionAttributeTypes = new ArrayList<DimensionAttributeType>();
//			dimensionAttributeTypes.addAll(dimensionAttributeTypes1);
//			if (dimensionAttributeTypes.contains(DimensionAttributeType.LOCATION_ID)) {
//				dimensionAttributeTypes.remove(DimensionAttributeType.LOCATION_ID);
//			}
//			parameter.put("dimensionAttributeTypes", dimensionAttributeTypes);
//			System.out.println(FreeMarkerUtil.processFile(AnalogyStatementInitializer.class, "43_WEEK_KPI_AGG-WEEK_KQI_AGG.ftl", parameter));
//		}
		
		//51_HOUR_KQI_AGG-HOUR_KQI_ACC.ftl
//		
//		for (AnalogyDimensionType analogyDimensionType : analogyDimensionTypes) {
//			MapParameter parameter = new MapParameter();
//			parameter.put("sourceTable", AnalogyTableNameUtil.tableName(analogyDimensionType, TimeDimensionType.HOUR, ProcessDimensionType.KQI_AGG));
//			parameter.put("targetTable", AnalogyTableNameUtil.tableName(analogyDimensionType, TimeDimensionType.HOUR, ProcessDimensionType.KQI_ACC));
//
//			DimensionAttributeType[] dimensionAttributeTypeArray = AnalogyDimensionAttributeType.getByAnalogyDimensionType(analogyDimensionType);
//			List<DimensionAttributeType> dimensionAttributeTypes1 = Arrays.asList(dimensionAttributeTypeArray);
//			List<DimensionAttributeType> dimensionAttributeTypes = new ArrayList<DimensionAttributeType>();
//			dimensionAttributeTypes.addAll(dimensionAttributeTypes1);
//			if (dimensionAttributeTypes.contains(DimensionAttributeType.LOCATION_ID)) {
//				dimensionAttributeTypes.remove(DimensionAttributeType.LOCATION_ID);
//			}
//			parameter.put("dimensionAttributeTypes", dimensionAttributeTypes);
//			System.out.println(FreeMarkerUtil.processFile(AnalogyStatementInitializer.class, "51_HOUR_KQI_AGG-HOUR_KQI_ACC.ftl", parameter));
//		}
		
		//52_DAY_KQI_AGG-DAY_KQI_ACC.ftl
//		
//		for (AnalogyDimensionType analogyDimensionType : analogyDimensionTypes) {
//			MapParameter parameter = new MapParameter();
//			parameter.put("sourceTable", AnalogyTableNameUtil.tableName(analogyDimensionType, TimeDimensionType.DAY, ProcessDimensionType.KQI_AGG));
//			parameter.put("targetTable", AnalogyTableNameUtil.tableName(analogyDimensionType, TimeDimensionType.DAY, ProcessDimensionType.KQI_ACC));
//
//			DimensionAttributeType[] dimensionAttributeTypeArray = AnalogyDimensionAttributeType.getByAnalogyDimensionType(analogyDimensionType);
//			List<DimensionAttributeType> dimensionAttributeTypes1 = Arrays.asList(dimensionAttributeTypeArray);
//			List<DimensionAttributeType> dimensionAttributeTypes = new ArrayList<DimensionAttributeType>();
//			dimensionAttributeTypes.addAll(dimensionAttributeTypes1);
//			if (dimensionAttributeTypes.contains(DimensionAttributeType.LOCATION_ID)) {
//				dimensionAttributeTypes.remove(DimensionAttributeType.LOCATION_ID);
//			}
//			parameter.put("dimensionAttributeTypes", dimensionAttributeTypes);
//			System.out.println(FreeMarkerUtil.processFile(AnalogyStatementInitializer.class, "52_DAY_KQI_AGG-DAY_KQI_ACC.ftl", parameter));
//		}

		//53_WEEK_KQI_AGG-WEEK_KQI_ACC.ftl
//		
//		for (AnalogyDimensionType analogyDimensionType : analogyDimensionTypes) {
//			MapParameter parameter = new MapParameter();
//			parameter.put("sourceTable", AnalogyTableNameUtil.tableName(analogyDimensionType, TimeDimensionType.WEEK, ProcessDimensionType.KQI_AGG));
//			parameter.put("targetTable", AnalogyTableNameUtil.tableName(analogyDimensionType, TimeDimensionType.WEEK, ProcessDimensionType.KQI_ACC));
//
//			DimensionAttributeType[] dimensionAttributeTypeArray = AnalogyDimensionAttributeType.getByAnalogyDimensionType(analogyDimensionType);
//			List<DimensionAttributeType> dimensionAttributeTypes1 = Arrays.asList(dimensionAttributeTypeArray);
//			List<DimensionAttributeType> dimensionAttributeTypes = new ArrayList<DimensionAttributeType>();
//			dimensionAttributeTypes.addAll(dimensionAttributeTypes1);
//			if (dimensionAttributeTypes.contains(DimensionAttributeType.LOCATION_ID)) {
//				dimensionAttributeTypes.remove(DimensionAttributeType.LOCATION_ID);
//			}
//			parameter.put("dimensionAttributeTypes", dimensionAttributeTypes);
//			System.out.println(FreeMarkerUtil.processFile(AnalogyStatementInitializer.class, "53_WEEK_KQI_AGG-WEEK_KQI_ACC.ftl", parameter));
//		}

		
		//60_HOUR_KQI_AGG_RANK.ftl				
		for (AnalogyDimensionType analogyDimensionType : analogyDimensionTypes) {
			MapParameter parameter = new MapParameter();
			parameter.put("sourceTable", AnalogyTableNameUtil.tableName(analogyDimensionType, TimeDimensionType.HOUR, ProcessDimensionType.KQI_AGG));
			

			DimensionAttributeType[] dimensionAttributeTypeArray = AnalogyDimensionAttributeType.getByAnalogyDimensionType(analogyDimensionType);
			List<DimensionAttributeType> dimensionAttributeTypes1 = Arrays.asList(dimensionAttributeTypeArray);
			List<DimensionAttributeType> dimensionAttributeTypes = new ArrayList<DimensionAttributeType>();
			dimensionAttributeTypes.addAll(dimensionAttributeTypes1);
			if (dimensionAttributeTypes.contains(DimensionAttributeType.LOCATION_ID)) {
				dimensionAttributeTypes.remove(DimensionAttributeType.LOCATION_ID);
			}
			parameter.put("dimensionAttributeTypes", dimensionAttributeTypes);
			System.out.println(FreeMarkerUtil.processFile(AnalogyStatementInitializer.class, "60_HOUR_KQI_AGG_RANK.ftl", parameter));
		}	
		
		//61_DAY_KQI_AGG_RANK.ftl
		for (AnalogyDimensionType analogyDimensionType : analogyDimensionTypes) {
			MapParameter parameter = new MapParameter();
			parameter.put("sourceTable", AnalogyTableNameUtil.tableName(analogyDimensionType, TimeDimensionType.DAY, ProcessDimensionType.KQI_AGG));
			
			DimensionAttributeType[] dimensionAttributeTypeArray = AnalogyDimensionAttributeType.getByAnalogyDimensionType(analogyDimensionType);
			List<DimensionAttributeType> dimensionAttributeTypes1 = Arrays.asList(dimensionAttributeTypeArray);
			List<DimensionAttributeType> dimensionAttributeTypes = new ArrayList<DimensionAttributeType>();
			dimensionAttributeTypes.addAll(dimensionAttributeTypes1);
			if (dimensionAttributeTypes.contains(DimensionAttributeType.LOCATION_ID)) {
				dimensionAttributeTypes.remove(DimensionAttributeType.LOCATION_ID);
			}
			parameter.put("dimensionAttributeTypes", dimensionAttributeTypes);
			System.out.println(FreeMarkerUtil.processFile(AnalogyStatementInitializer.class, "61_DAY_KQI_AGG_RANK.ftl", parameter));
		}	
		
		//62_WEEK_KQI_AGG_RANK.ftl
		for (AnalogyDimensionType analogyDimensionType : analogyDimensionTypes) {
			MapParameter parameter = new MapParameter();
			parameter.put("sourceTable", AnalogyTableNameUtil.tableName(analogyDimensionType, TimeDimensionType.WEEK, ProcessDimensionType.KQI_AGG));
			
			DimensionAttributeType[] dimensionAttributeTypeArray = AnalogyDimensionAttributeType.getByAnalogyDimensionType(analogyDimensionType);
			List<DimensionAttributeType> dimensionAttributeTypes1 = Arrays.asList(dimensionAttributeTypeArray);
			List<DimensionAttributeType> dimensionAttributeTypes = new ArrayList<DimensionAttributeType>();
			dimensionAttributeTypes.addAll(dimensionAttributeTypes1);
			if (dimensionAttributeTypes.contains(DimensionAttributeType.LOCATION_ID)) {
				dimensionAttributeTypes.remove(DimensionAttributeType.LOCATION_ID);
			}
			parameter.put("dimensionAttributeTypes", dimensionAttributeTypes);
			System.out.println(FreeMarkerUtil.processFile(AnalogyStatementInitializer.class, "62_WEEK_KQI_AGG_RANK.ftl", parameter));
		}	
	}

}
